package com.pisolution.scheduler.runtime.context;

import com.pisolution.scheduler.core.utils.JsonUtils;
import com.pisolution.scheduler.remote.command.Command;
import com.pisolution.scheduler.remote.command.CommandConverter;
import com.pisolution.scheduler.remote.command.CommandType;

/**
 * 用于管理节点告知工作节点予以执行给定的任务并告知任务执行时的上下文环境.
 *
 * @author sora
 * @version 0.1.0
 */
public final class TaskExecuteCommand implements CommandConverter {
    private static final long serialVersionUID = -4627122811301062035L;

    // -------------------------------------------------------------------------------------------------

    /** 待执行任务的上下文环境. */
    private String context;

    // -------------------------------------------------------------------------------------------------
    //  属性访问
    // -------------------------------------------------------------------------------------------------

    public String getContext() {
        return this.context;
    }

    public void setContext(String context) {
        this.context = context;
    }

    // -------------------------------------------------------------------------------------------------
    //  指令转换
    // -------------------------------------------------------------------------------------------------

    @Override
    public Command convert() {
        final Command command = new Command();

        command.setType(CommandType.TASK_EXECUTE_REQUEST);
        command.setBody(JsonUtils.serialize(this));

        return command;
    }
}
